package zucc.edu.repay.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import Bean.role;
import Util.BaseException;
import Util.HibernateUtil;

public class RoleDao {
	public void delRole(role role) {
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		s.delete(role);
		tx.commit();
		
	}
	
	public void addRole(role role) {
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		s.save(role);
		tx.commit();
				
	}
	
	public void updateRole(role role) {
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		s.update(role);
		tx.commit();
		
	}
	
	public role searchRole(String roleid) throws BaseException{
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		String hql = "from role where roleid = '" + roleid + "'";
		Query qry = s.createQuery(hql);
		Object role = qry.uniqueResult();
		tx.commit();
		return (role)role;
	}
	
	public List<role> serarchAllRole(){//�������û�
		Session s = HibernateUtil.getSessionFactory().getCurrentSession(); 
		Transaction tx = s.beginTransaction();
        String hql = "from role";  
        Query query = s.createQuery(hql);  
        List<role> roles = query.list();  
        tx.commit();
        return roles; 
}
}
